package com.atwork.wuhua.mvp.presenter;

import com.atwork.wuhua.base.BasePresenter;
import com.atwork.wuhua.base.BaseReq;
import com.atwork.wuhua.base.MyApplication;
import com.atwork.wuhua.bean.EvaluateBean;
import com.atwork.wuhua.bean.SubDetailBean;
import com.atwork.wuhua.bean.SubDetailNumBean;
import com.atwork.wuhua.mvp.Callback;
import com.atwork.wuhua.mvp.DataModel;
import com.atwork.wuhua.mvp.Token;
import com.atwork.wuhua.mvp.view.ISubDetailActivity;

public class SubDetailPresenter extends BasePresenter<ISubDetailActivity> {

    /**
     * 获取约战详情
     *
     * @param id
     */
    public void getData(String id) {
        showLoading();
        BaseReq req = new BaseReq();
        req.setKey("id", id);
        DataModel.request(Token.API_SUB_DETAIL)
                .params(req)
                .execute(new Callback<SubDetailBean>() {

                    public void onSuccess(String msg, SubDetailBean data) {
                        getView().setData(data);
                        hideLoading();
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    /**
     * 获取约战参与人数
     *
     * @param id
     */
    public void getJoinNum(String id) {
        BaseReq req = new BaseReq();
        req.setKey("id", id);
        DataModel.request(Token.API_SUB_JOIN_NUM)
                .params(req)
                .execute(new Callback<SubDetailNumBean>() {

                    public void onSuccess(String msg, SubDetailNumBean data) {
                        getView().setJoinData(data);
                        hideLoading();
                    }

                    @Override
                    public void onFailure(String msg) {
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }


    /**
     * 参与约战
     *
     * @param id
     */
    public void postJoin(String id) {
        showLoading();
        BaseReq req = new BaseReq();
        req.setKey("uuid", MyApplication.UUID);
        req.setKey("id", id);
        DataModel.request(Token.API_SUB_JOIN)
                .params(req)
                .execute(new Callback<String>() {

                    public void onSuccess(String msg, String data) {
                        hideLoading();
                        getView().joinResult();
                    }

                    @Override
                    public void onFailure(String msg) {
                        showToast(msg);
                        hideLoading();
                    }

                    @Override
                    public void onError() {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
